package com.shg.web.action;

import java.net.URLDecoder;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;
import com.shg.bean.Online;
import com.shg.bean.Shop;
import com.shg.service.OnlineService;
import com.shg.web.tools.WebTool;

@Controller
public class OnlineAction extends ActionSupport {

	//信息
	private String message;
	//在线客服
	private List<Online> onlines;
	//
	private Online online;
	//店铺
	private Shop shop;
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@Resource OnlineService onlineService;
	/**
	 * 店铺的客服查询
	 * @return
	 */
	public String list(){
		try {
			onlines = onlineService.getOnline(WebTool.getLogin().getId());
		} catch (Exception e) {
			e.printStackTrace();
			this.message="查询发送异常";
			return ERROR;
		}
		return "list";
	}
	public String addOnlineUI(){
		return "addOnlineUI";
	}
	/**
	 * 添加客服
	 * @return
	 */
	public String addOnline(){
		try{
			if(online!=null){
				Shop shop=new Shop();
				shop.setId(WebTool.getLogin().getId());
				online.setShop(shop);
				onlineService.insert(online);
			}
		}catch (Exception e) {
			e.printStackTrace();
			this.message="添加客服发送异常";
			return ERROR;
		}
		return list();
	}
	/**
	 * 
	 * @return
	 */
	public String deleteOnline(){
		try {
			onlineService.removeOnline(online);
		} catch (Exception e) {
			e.printStackTrace();
			this.message="删除客服出现异常";
			return ERROR;
		}
		return list();
	}
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
	public List<Online> getOnlines() {
		return onlines;
	}
	public void setOnlines(List<Online> onlines) {
		this.onlines = onlines;
	}
	public Shop getShop() {
		return shop;
	}
	public void setShop(Shop shop) {
		this.shop = shop;
	}
	public Online getOnline() {
		return online;
	}
	public void setOnline(Online online) {
		this.online = online;
	}

}
